Tweak gpsutil to become a real fixed-length field format.
authoroliskoli <oliskoli>
Tue, 29 Aug 2006 22:01:11 +0000 (22:01 +0000)
committeroliskoli <oliskoli>
Tue, 29 Aug 2006 22:01:11 +0000 (22:01 +0000)
Add special code for old, non-fixed-length files.
Rebuilt reference data for gpsutil testo sequence.
Force usage of common gbfile api.

gpsutil.c
reference/ov2-in.ref

index ed82be57c56f703a73fc70b735e7f1b173f1e6d6..8e5e6c2bc9484b3642f291b4d5b432eb6dafe9bc 100644 (file)
--- a/gpsutil.c
+++ b/gpsutil.c
@@ -21,8 +21,7 @@
 #include "defs.h"
 #include "magellan.h"
 
-static FILE *file_in;
-static FILE *file_out;
+static gbfile *file_in, *file_out;
 static short_handle mkshort_handle;
 
 #define MYNAME "GPSUTIL"
@@ -30,26 +29,26 @@ static short_handle mkshort_handle;
 static void
 rd_init(const char *fname)
 {
-       file_in = xfopen(fname, "rb", MYNAME);
+       file_in = gbfopen(fname, "rb", MYNAME);
 }
 
 static void
 rd_deinit(void)
 {
-       fclose(file_in);
+       gbfclose(file_in);
 }
 
 static void
 wr_init(const char *fname)
 {
-       file_out = xfopen(fname, "w", MYNAME);
+       file_out = gbfopen(fname, "w", MYNAME);
        mkshort_handle = mkshort_new_handle();
 }
 
 static void
 wr_deinit(void)
 {
-       fclose(file_out);
+       gbfclose(file_out);
        mkshort_del_handle(&mkshort_handle);
 }
 
@@ -57,44 +56,53 @@ static void
 data_read(void)
 {
        char *ibuf;
-       char name[9], desc[31];
+       char desc[31];
        double lat,lon;
        char latdir, londir;
        int ilat, ilon;
        long alt; 
        char alttype;
-       char icon[3] = {0};
+       char icon[3];
        waypoint *wpt_tmp;
-       textfile_t *tin;
+
        /*
         * Make sure that all waypoints in single read have same 
         * timestamp.
         */
        time_t now = current_time();
        
-       tin = textfile_init(file_in);
-
-       while ((ibuf = textfile_read(tin))) {
-               int n;
+       while ((ibuf = gbfgetstr(file_in))) {
+               int n, len;
+               char *sn;
        /*  A sharp in column zero or an blank line is a comment */
                ibuf = lrtrim(ibuf);
-               if (ibuf[0] == '#' || ibuf[0] == '\n') continue;
-               n = sscanf(ibuf, "%s %le%c %le%c %ld%c %30[^,] %c",
-                       name, &lat, &latdir, &lon, &londir,
+               len = strlen(ibuf);
+               if ((len == 0) || (*ibuf == '#')) continue;
+               
+               if (len > 71) {
+                       int offs = len - 71;
+                       sn = xstrndup(ibuf, offs + 8);
+                       ibuf += (offs + 9);
+               }
+               else {
+                       sn = xstrndup(ibuf, 8);
+                       ibuf += 9;
+               }
+               
+               n = sscanf(ibuf, "%lf%c %lf%c %ld%c %30[^,]s %2s",
+                       &lat, &latdir, &lon, &londir,
                        &alt, &alttype, desc, icon);
                /* Require at least first threee fields, otherwise ignore */
-               if (n < 3) { 
+               if (n < 2) { 
+                       xfree(sn);
                        continue;
                }
-               desc[0] = '\0';
-               icon[0] = '\0';
-               sscanf(&ibuf[39], "%30c", desc);
-               sscanf(&ibuf[70], "%2c", icon);
+               rtrim(sn);
                rtrim(desc);
                rtrim(icon);
                wpt_tmp = waypt_new();
                wpt_tmp->altitude = alt;
-               wpt_tmp->shortname = xstrdup(name);
+               wpt_tmp->shortname = sn;
                wpt_tmp->description = xstrdup(desc);
                wpt_tmp->creation_time = now;
 
@@ -110,7 +118,6 @@ data_read(void)
                wpt_tmp->icon_descr = mag_find_descr_from_token(icon);
                waypt_add(wpt_tmp);
        }
-       textfile_done(tin);
 }
 
 static void
@@ -125,7 +132,7 @@ gpsutil_disp(const waypoint *wpt)
        lon = degrees2ddmm(wpt->longitude);
        lat = degrees2ddmm(wpt->latitude);
 
-       fprintf(file_out, "%-8s %08.3f%c %09.3f%c %07.0f%c %-30.30s %s\n",
+       gbfprintf(file_out, "%-8.8s %08.3f%c %09.3f%c %07.0f%c %-30.30s %s\n",
                 global_opts.synthesize_shortnames ?
                         mkshort_from_wpt(mkshort_handle, wpt) : 
                        wpt->shortname,
index 4c0e75deecd82d968d197c1a598817afd05b897f..8ce96c6f24b777c1e3c5c3bf50add2f4a9e0cb9b 100644 (file)
@@ -1,9 +1,9 @@
-Mountain Bike Heaven by susy1313 3558.322N 08708.081W 0000000m Mountain Bike Heaven by susy13 a
-The Troll by a182pilot & Family 3605.441N 08640.772W 0000000m The Troll by a182pilot & Famil a
-Dive Bomber by JoGPS & family 3559.776N 08637.207W 0000000m Dive Bomber by JoGPS & family  a
-FOSTER by JoGPS & Family 3602.309N 08638.917W 0000000m FOSTER by JoGPS & Family       a
-Logan Lighthouse by JoGps & Family 3606.731N 08644.506W 0000000m Logan Lighthouse by JoGps & Fa a
-Ganier Cache by Susy1313 3603.845N 08647.431W 0000000m Ganier Cache by Susy1313       a
-Shy's Hill by FireFighterEng33 3605.266N 08648.583W 0000000m Shy's Hill by FireFighterEng33 a
-GittyUp by JoGPS / Warner Parks 3603.450N 08653.519W 0000000m GittyUp by JoGPS / Warner Park a
-Inlighting by JoGPS / Warner Parks 3604.968N 08652.036W 0000000m Inlighting by JoGPS / Warner P a
+Mountain 3558.322N 08708.081W 0000000m Mountain Bike Heaven by susy13 a
+The Trol 3605.441N 08640.772W 0000000m The Troll by a182pilot & Famil a
+Dive Bom 3559.776N 08637.207W 0000000m Dive Bomber by JoGPS & family  a
+FOSTER b 3602.309N 08638.917W 0000000m FOSTER by JoGPS & Family       a
+Logan Li 3606.731N 08644.506W 0000000m Logan Lighthouse by JoGps & Fa a
+Ganier C 3603.845N 08647.431W 0000000m Ganier Cache by Susy1313       a
+Shy's Hi 3605.266N 08648.583W 0000000m Shy's Hill by FireFighterEng33 a
+GittyUp  3603.450N 08653.519W 0000000m GittyUp by JoGPS / Warner Park a
+Inlighti 3604.968N 08652.036W 0000000m Inlighting by JoGPS / Warner P a